<?php
	require_once("conn.php");
	require_once("smarty/Smarty.class.php");
	session_start();
	if(isset($_POST['radiobutton'])){
		$_SESSION['flag'] = $_POST['radiobutton'];
	}
	if(!(isset($_POST['keyword']))){

		header("Location: index.php");
	}
	else{

		$keyword = $_POST['keyword'];
	}

	//about types

	mysql_select_db($dataname,$conn);
	$query_rs_types = "select * from types order by type_id ASC";
	mysql_query("set names 'gbk'");
	$rs_types = mysql_query($query_rs_types,$conn) or die(mysql_error());
	$array_rs_types = array();
	$array_rs_type_name = array();
	$array_rs_type_id = array();

	while($row_rs_types = mysql_fetch_assoc($rs_types)){
		array_push($array_rs_types,$row_rs_types);
		array_push($array_rs_type_name,$row_rs_types['type_name']);
		array_push($array_rs_type_id,$row_rs_types['type_id']);
	}

	//about article

	mysql_select_db($dataname,$conn);
	$query_rs_articles = "select * from articles where title like '%".$keyword."%'";
	mysql_query("set names 'gbk'");
	$rs_articles = mysql_query($query_rs_articles,$conn) or die(mysql_error());
	$rs_articles_num = mysql_num_rows($rs_articles);
	$array_rs_articles = array();
	while($row_rs_articles = mysql_fetch_assoc($rs_articles)){
		array_push($array_rs_articles,$row_rs_articles);
	}


	//about config

	mysql_select_db($dataname,$conn);
	$query_rs_config = "select * from config";
    $rs_config = mysql_query($query_rs_config,$conn) or die(mysql_error());
	$row_rs_config = mysql_fetch_assoc($rs_config);
	$row_rs_config_copyright = $row_rs_config['copyright'];

	//about Smarty

	$smarty = new Smarty;
	$smarty->left_delimiter = '[{';
	$smarty->right_delimiter = '}]';
	$smarty->assign("array_rs_types",$array_rs_types);
	$smarty->assign("array_rs_type_name",$array_rs_type_name);
	$smarty->assign("array_rs_type_id",$array_rs_type_id);
	$smarty->assign("array_rs_articles",$array_rs_articles);
    $smarty->assign("row_rs_config_copyright",$row_rs_config_copyright);
	$smarty->assign("rs_articles_num",$rs_articles_num);
	$smarty->assign("keyword",$keyword);
	$smarty->display('search'.$_SESSION['flag'].'.tpl');


?>